import axios from 'axios'

const request = axios.create({
    baseURL: "https://m.maizuo.com/gateway"
})

  
  
  // 请求拦截
  request.interceptors.request.use(
    (config) => {
      const { token } = JSON.parse(localStorage.getItem("user") || "{}");
      if (token) {
        (config.headers as any).token = token;
      }
  
      return config;
    },
    (error) => {
      return Promise.reject(error);
    }
  );
  
  // 响应拦截
  request.interceptors.response.use(
    (response) => {
      // 2xx 进入
      const { data } = response;
  
      // 判断业务状态码是否为 '200'
      if (data.code === "200") {
        return data;
      } else {
      
      }
    },
    (error) => {
      // 2xx 之外的进入
  
      });
  
  export default request;